#include <iostream>


using namespace std;

class SeqStack{
private:
    int top_;
    int cap_;
    int *s_ptr;

private:
    void resize(int cap);

public:
    SeqStack(int cap = 10)
        :top_(-1)
        ,cap_(cap)
    {
        s_ptr = new int[cap_];
    }
    ~SeqStack()
    {
        delete []s_ptr;
    }
    void push(int val);
    int pop();
    int top() const;
    bool empty() const;
    int size() const;
};

void SeqStack::resize(int cap){
    int *new_s_ptr = new int[cap];
    for(int i = 0; i <= top_; ++i){
        new_s_ptr[i] = s_ptr[i];
    }
    delete []s_ptr;
    s_ptr = new_s_ptr;
    cap_ = cap;
}

void SeqStack::push(int val){
    if(top_ == cap_ - 1){
        resize(2 * cap_);
    }
    s_ptr[++top_] = val;
}

int SeqStack::pop(){
    if(top_ == -1){
        throw "stack is empty";
    }
    return s_ptr[top_--];
}

int SeqStack::top() const{
    if(top_ == -1){
        throw "stack is empty";
    }
    return s_ptr[top_];
}

bool SeqStack::empty() const{
    return top_ == -1;
}

int SeqStack::size() const{
    return top_ + 1;
}


int main(){
    SeqStack s;
    int arr[] = {1,2,3,4,5,6,7,8,9,10};
    for (int val : arr){
        s.push(val);
        cout << "top is " << s.top() << endl;
    }
    cout << "size is " << s.size() << endl;
    int length = s.size();
    for (size_t i = 0; i < length; i++)
    {
        cout << s.pop() << endl;
        cout << "i is " << i << endl;
    }
    cout << "stack is empty : " << s.empty() << endl;
    
    return 0;
}